<?php

namespace App\Jobs;

use Carbon\Carbon;
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use App\Services\CloseUnpaidProductOrder\CloseUnpaidProductOrder;
use App\Services\MakeSeckillOrder\CloseUnpaidSeckillOrder;

class CloseOrderJob implements ShouldQueue
{
   use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected int $uid;
    protected string $unpaidCacheId;

    public function __construct($uid, $unpaidCacheId)
    {
        $this->uid = $uid;
        $this->unpaidCacheId = $unpaidCacheId;
        $this->delay(Carbon::now()->addHours(24));
    }

    public function handle()
    {
        app(CloseUnpaidSeckillOrder::class, [
            'uid' => $this->uid,
            'unpaidCacheId' => $this->unpaidCacheId
        ])->close();
    }
}
